<template>
  <div>
  
    <a-card>
      
      <a-form :form="form">
       
        <a-row>
          <a-col :md="24" :sm="24">
            <a-col :md="12" :sm="24">
              <a-form-item
                label="学科专业码"
                :labelCol="{span: 7,offset: 1}"
                :wrapperCol="{span: 15, offset: 1}"
              >
                <a-input v-decorator="[
                  'xkzym',
                  {
                    rules: [{ required: true, message: '请输入教学科专业码!' }],
                  }
                ]"/>
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="24">
              <a-form-item
                label="学科专业名称"
                :labelCol="{span: 7,offset: 1}"
                :wrapperCol="{span: 15, offset: 1}"
              >
                <a-input style="width:70%;" v-model="xkmc" disabled/>
                <a-button style="margin-left: 2%;width: 28%;" type="primary" @click="handleSearch">查询</a-button>
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="24">
              <a-form-item
                label="招生年度"
                :labelCol="{span: 7,offset: 1}"
                :wrapperCol="{span: 15, offset: 1}"
              >
                <a-select v-decorator="['zsnj',
                  {
                    rules: [{ required: true, message: '招生年度' }],
                  }]" disabled>
                  <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="24">
              <a-form-item
                label="外语听力"
                :labelCol="{span: 7,offset: 1}"
                :wrapperCol="{span: 15, offset: 1}"
              >
                <a-input v-decorator="[
                  'wytlfsx',
                  {
                    rules: [{ required: true, message: '请输入外语听力!' }],
                  }
                ]"/>
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="24">
              <a-form-item
                label="外语笔试"
                :labelCol="{span: 7,offset: 1}"
                :wrapperCol="{span: 15, offset: 1}"
              >
                <a-input v-decorator="[
                  'wybsfsx',
                  {
                    rules: [{ required: true, message: '请输入外语笔试!' }],
                  }
                ]"/>
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="24">
              <a-form-item
                label="外语口语"
                :labelCol="{span: 7,offset: 1}"
                :wrapperCol="{span: 15, offset: 1}"
              >
                <a-input v-decorator="[
                  'wykyfsx',
                  {
                    rules: [{ required: true, message: '请输入外语口语!' }],
                  }
                ]"/>
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="24">
              <a-form-item
                label="外语总分"
                :labelCol="{span: 7,offset: 1}"
                :wrapperCol="{span: 15, offset: 1}"
              >
                <a-input v-decorator="[
                  'wyzffsx',
                  {
                    rules: [{ required: true, message: '请输入外语总分!' }],
                  }
                ]"/>
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="24">
              <a-form-item
                label="业务课一"
                :labelCol="{span: 7,offset: 1}"
                :wrapperCol="{span: 15, offset: 1}"
              >
                <a-input v-decorator="[
                  'ywkyfsx',
                  {
                    rules: [{  required: true,message: '请输入业务课一!' }],
                  }
                ]"/>
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="24">
              <a-form-item
                label="业务课二"
                :labelCol="{span: 7,offset: 1}"
                :wrapperCol="{span: 15, offset: 1}"
              >
                <a-input v-decorator="[
                  'ywkefsx',
                  {
                    rules: [{  message: '请输入业务课二!' }],
                  }
                ]"/>
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="24">
              <a-form-item
                label="业务课三"
                :labelCol="{span: 7,offset: 1}"
                :wrapperCol="{span: 15, offset: 1}"
              >
                <a-input v-decorator="[
                  'ywksfsx',
                  {
                    rules: [{  message: '请输入业务课三!' }],
                  }
                ]"/>
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="24">
              <a-form-item
                label="业务课总成绩"
                :labelCol="{span: 7,offset: 1}"
                :wrapperCol="{span: 15, offset: 1}"
              >
                <a-input v-decorator="[
                  'ywkzcjfsx',
                  {
                    rules: [{ required: true, message: '请输入业务课总成绩!' }],
                  }
                ]"/>
              </a-form-item>
            </a-col>
          </a-col>
        </a-row>
      </a-form>
    </a-card>

    <div class="ant-pro-footer-toolbar">
      <a-button style="float: right;margin-top: 10px;" @click="handleSubmit" :loading="loadingBtn" type="primary">保存</a-button>
    </div>
  </div>
</template>
<script>
import { mapState } from 'vuex'
const selectArr = ['TYPE0126']

export default {
  data () {
    return {
      selectMenu: {},
      loading: false,
      imageUrl: '',
      loadingBtn: false,
      xkmc:''
    }
  },
  beforeCreate () {
    this.form = this.$form.createForm(this)
  },
  computed: {
   ...mapState({
      systemInfo: state => state.app.systemInfo,
      TYPE0126: state => state.app['TYPE0126'] // 年级
    })
  },
  created () {
    selectArr.forEach(v => {
      this.$store.dispatch('app/setDictionary', v)
    })
    this.initSelectMenu()
  },
  methods: {
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll(),
        this.$api.base.areaList()
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yx: res[0].data
        }
      })
       this.$api.base.getSchoolYear().then(res=>{
        this.form.setFieldsValue({'zsnj':res.data.doctoralAdmissionYear})
      })
    },
    handleSearch () {
      console.log(this.form.getFieldsValue().xkzym);
      
      
      if(this.form.getFieldsValue().xkzym=='' || typeof(this.form.getFieldsValue()).xkzym == "undefined"){
        this.xkmc='';
      }else{
           let parms={'xkzym':this.form.getFieldsValue().xkzym}
         this.$api.base.getMajor(parms).then(res=>{
           if(res.data){
             this.xkmc=res.data.xkmc;
           }
         })
      }
    },
    handleSubmit () {
       this.form.validateFields((err, values) => {
          if (err) {
            this.$message.error('请输入必填项')
            return
          }
      this.form.getFieldsValue().xkmc=this.xkmc;
      var params = Object.assign({xkmc:this.xkmc},this.form.getFieldsValue())
      console.log(this.form.getFieldsValue());
        this.$api.doctorRecruit.specialtySave(params).then(res => {
      	 this.$message.success(res.msg)
      	// this.$emit('success')
      }).finally(() => {
      	this.loadingBtn = false
        this.form.setFieldsValue({'xkzym':'','wytlfsx':'','wybsfsx':'','wykyfsx':'','wyzffsx':'','ywkyfsx':'','ywkefsx':'','ywksfsx':'','ywkzcjfsx':''})
        this.xkmc='';
      })
    })
    }
  }
}
</script>
